/*
	File:	video/model/Mesh.hpp
	Date:	2013-06-01
	Author:	Asteroth
*/


#ifndef __ZEN_MODEL_MESH_HPP__
#define __ZEN_MODEL_MESH_HPP__

#include "../../gl.hpp"
#include "../../math.hpp"

namespace zen {

	namespace video {

		namespace model {

			class Mesh {

			public:

				Mesh();
				Mesh(const Mesh &other); // very heavy operation
				~Mesh();

				Mesh& operator = (const Mesh &other); // very heavy operation
	
				glm::u32vec3* getIndexes() const { return indexes; }
				glm::uint getIndexCount() const { return indexCount; }
				glm::uint getIndexSize() const { return sizeof(glm::u32vec3); }

				glm::f32vec3* getVertexes() const { return vertexes; }
				glm::uint getVertexCount() const { return vertexCount; }
				glm::uint getVertexSize() const { return sizeof(glm::f32vec3); }

				void free() { free(true); }

				void update();
				void draw() const;

				bool loadResource(jsl::Node* node);

				
			private:

				GLuint				vertexArray;
				GLuint				indexBuffer;
				GLuint				vertexBuffer;
				GLuint				texCoordBuffer;
				GLuint				normalBuffer;
				GLuint				colorBuffer;

				glm::uint			indexCount;
				glm::uint			vertexCount;

				glm::u32vec3*		indexes;			// [indexCount]
				glm::f32vec3*		vertexes;			// [vertexCount]
				glm::f32vec3*		normals;			// [vertexCount]
				glm::f32vec2*		texCoords;			// [vertexCount]
				glm::u8vec4*		colors;				// [vertexCount]

				glm::f32vec3*		resultVertexes;		// [vertexCount]
				glm::f32vec3*		resultNormals;		// [vertexCount]
				glm::f32vec2*		resultTexCoords;	// [vertexCount]

				inline void init();
				inline void free(bool reinitialize);
		
			};

	
		} // namespace model

	} // namespace video

} // namespace zen

#endif
